package com.administrator.shiniang;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.TextView;

public class TranslationAnimationActivity extends Activity implements
        View.OnClickListener {
    private TextView mMenu;
    private Button mButton;
    private TranslateAnimation mShowAnimation;
    private TranslateAnimation mHideAnimation;
    private boolean isShow;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_translation_animation);

        initView();
        initAnimation();
    }

    private void initView() {
        mMenu = (TextView) findViewById(R.id.menu);
        mButton = (Button) findViewById(R.id.button);
        mButton.setOnClickListener(this);
        mMenu.setVisibility(View.GONE);
        isShow = false;
    }

    private void initAnimation() {
        // 从自已-1倍的位置移到自己原来的位置
        mShowAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
                0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF,
                0.0f);
        mHideAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
                0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF,
                1.0f);
        mShowAnimation.setDuration(500);
        mHideAnimation.setDuration(500);

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.button) {
            if (isShow) {
                isShow = false;
                mMenu.startAnimation(mHideAnimation);
                mMenu.setVisibility(View.GONE);
            } else {
                isShow = true;
                mMenu.startAnimation(mShowAnimation);
                mMenu.setVisibility(View.VISIBLE);
            }
        }
    }
}
